package com.postgresql.service;


import com.postgresql.dao.PoiDao;
import com.postgresql.dto.Poi;
import com.postgresql.dto.Test;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.WKTReader;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 顾志杰
 */
@Service
@Slf4j
public class PoiService {


    @Autowired
    private PoiDao poiDao;



    public void insert()throws Exception{
        Poi poi = new Poi();
        poi.setGid(24);
        poi.setName("顾志杰测试1");
        poi.setUserid(0);
        WKTReader wktReader = new WKTReader();
        Geometry poing = wktReader.read("POINT(14093101.5979161 14093101.5979161)");
        com.vividsolutions.jts.geom.Point interiorPoint = poing.getInteriorPoint();
        interiorPoint.setSRID(3857);
        poi.setGeom(interiorPoint);
        Poi save = poiDao.save(poi);
        log.info("添加成功 id = {}",save.getGid());
    }

    public List<Poi> query(){
        Test test = poiDao.findTest();
        return poiDao.findAll();
    }
}
